package puzzle.projecteuler.p100;

import java.math.BigInteger;

import org.apache.commons.lang.StringUtils;

public class Problem055 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		int c = 0;
		for (int i = 0; i < 10000; i ++) {
			BigInteger a = BigInteger.valueOf(i);
			for (int j = 0; j < 50; j ++) {
				a = a.add(reverse(a));
				if (isPalindromic(a)) {
					c ++;
					break;
				}
			}
		}
		System.out.println(10000-c);
	}

	public static BigInteger reverse(BigInteger a) {

		return new BigInteger(StringUtils.reverse(a.toString()));
	}
	
	public static boolean isPalindromic(BigInteger a) {
		String t = a.toString();
		String r = StringUtils.reverse(t);
		return t.equalsIgnoreCase(r);
	}
}
